home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 6984 / 6984.xpi / chrome / lazarus.jar / content / password.js < prev    next >
Text File  |  2009-11-24  |  3KB  |  80 lines

  1.  
  2. Lazarus.db = Lazarus.getBrowser().Lazarus.db;
  3. Lazarus.Crypto = Lazarus.getBrowser().Lazarus.Crypto;
  4.  
  5. function init(){
  6.     if (!Lazarus.getBrowser().Lazarus.isPasswordSet()){
  7.         //disable the Current password box
  8.         document.getElementById('previous').hidden = true;
  9.         document.getElementById('previous-disabled').hidden = false;
  10.     }
  11.     else {
  12.         document.getElementById('previous').hidden = false;
  13.         document.getElementById('previous-disabled').hidden = true;
  14.     }
  15. }
  16.  
  17.  
  18. function refreshButtons(){
  19.     var btnAccept = document.getElementsByTagName('dialog')[0].getButton('accept');
  20.     btnAccept.disabled = (document.getElementById('password').value != document.getElementById('confirm').value);
  21. }
  22.  
  23. /**
  24. */
  25. function onAccept(){
  26.     //re-encrypt the private key with the new password.
  27.     var previousBox = document.getElementById('previous');
  28.     var passwordBox = document.getElementById('password');
  29.     var confirmBox = document.getElementById('confirm');
  30.     
  31.     var encb64Key = Lazarus.db.getStr("SELECT value FROM settings WHERE name = 'private-key'");
  32.     //we need to unencrypt the private key
  33.     var decb64Key = Lazarus.Crypto.AESDecrypt(encb64Key, previousBox.value);
  34.  
  35.     //incorrect old password
  36.     if (!decb64Key){
  37.         alert(strings["error-incorrect-password"]);
  38.         previousBox.value = '';
  39.         return false;
  40.     }
  41.     //passwords don't match
  42.     else if (passwordBox.value != confirmBox.value){
  43.         alert(strings["error-password-mismatch"]);
  44.         passwordBox.value = '';
  45.         confirmBox.value = '';
  46.         passwordBox.focus();
  47.         return false;
  48.     }
  49.     //same password as before
  50.     else if (previousBox.value == passwordBox.value){
  51.         return true;
  52.     }
  53.     //password changed 
  54.     else {
  55.         //re-encrypt the private key with the new password, and save it.
  56.         var newb64Key = Lazarus.Crypto.AESEncrypt(decb64Key, passwordBox.value);
  57.         
  58.         //and save
  59.         Lazarus.db.exe("DELETE FROM settings WHERE name = 'private-key'");
  60.         Lazarus.db.exe("INSERT INTO settings (name, value) VALUES ('private-key', ?1)", newb64Key);
  61.         //since we've changed the password, we'd better log the user out 
  62.         Lazarus.getBrowser().Lazarus.unloadPrivateKey(); 
  63.         
  64.         //if the user has removed the password, then log em in again
  65.         if (passwordBox.value == ''){
  66.             Lazarus.getBrowser().Lazarus.loadPrivateKey();
  67.             //and remove the password from the SSD if it exists
  68.             Lazarus.getBrowser().Lazarus.removePassword();            
  69.         }
  70.         //if the user has his password stored in the Software Security Device, then we should update that as well.
  71.         else if (previousBox.value && Lazarus.getBrowser().Lazarus.loadPassword() == previousBox.value){
  72.             Lazarus.getBrowser().Lazarus.savePassword(passwordBox.value);
  73.         }
  74.         return true;
  75.     }
  76. }
  77.  
  78.  
  79.